var Principal = Ext
		.extend(
				Ext.util.Observable,
				{
					constructor : function() {
						this.tema = 2;
						this.tabPanelCentral = new Ext.TabPanel(
								{
									region : "center",
									enableTabScroll : true,
									activeTab : 0,
									defaults : {
										closable : true
									},
									items : [ {
										title : "Home",
										html : '<div id="principal"><a target="_blank" href="http://www.assembleiadedeus.org.br"><img alt="" src="img/ieadc.png" align="right"></a><h1 style="font-family:helvetica,tahoma,verdana,sans-serif; font-size:large; margin-bottom:20px;">Seja bem vindo!</h1><p style="font-family:helvetica,tahoma,verdana,sans-serif; font-size:13px;">Navegue pelo menu lateral.</p></div>',
										bodyStyle : "padding:10px;",
										iconCls : "silk-home",
										closable : false
									} ],
									plugins : new Ext.ux.TabCloseMenu(
											{
												closeTabText : "Fechar aba",
												closeOtherTabsText : "Fechar as outras abas",
												closeAllTabsText : "Fechar todas as abas"
											})
								});
						this.menu = new Ext.Viewport(
								{
									layout : "border",
									items : [
											{
												region : "north",
												border : false,
												height : 28,
												xtype : "box",
												renderTo : Ext.getBody(),
												html : '<div id="header"><span style="float:right;margin-right:10px; margin-top:3px; font-style: normal; color: white;"><b>' + window.dataServer.nomeUsuario + '</b>&nbsp;|&nbsp;<a href="javascript:exibirJanelaAjuda()" style="text-decoration: none; font-style: normal; color: white;"><img src="lib/ext3.2.1/ux/images/question.png"/>&nbsp;Ajuda</a>&nbsp;|&nbsp;<a href="javascript:sair()" style="text-decoration: none; font-style: normal; color: white;"><img src="lib/ext3.2.1/ux/images/door_out.png"/>&nbsp;Sair</a></span><div class="titulo"><a href="javascript:exibirJanelaSobre()" style="text-decoration: none; color: white;">SIAD - Sistema de Informação Assembleia de Deus</a></div></div>'
											},
											{
												id : "menus",
												region : "west",
												title : "Menu",
												layout : "accordion",
												defaultType : "treepanel",
												width : 210,
												minSize : 210,
												maxSize : 210,
												split : true,
												layoutConfig : {
													fill : false,
													animate : true
												},
												defaults : {
													border : false,
													rootVisible : false,
													listeners : {
														scope : this,
														click : this.onNodeClick
													}
												},
												items : [
														{
															title : "Secretaria",
															id : "secretaria",
															hidden : true,
															iconCls : "silk-secretaria",
															root : {
																children : [
																		{
																			text : "Membros/Congregados",
																			name : "secretaria",
																			leaf : true,
																			iconCls : "silk-membro",
																			eXtype : "MembroLista"
																		},
																		{
																			text : "Patrimônios",
																			name : "secretaria",
																			leaf : true,
																			iconCls : "silk-patrimonio",
																			eXtype : "PatrimonioLista"
																		} ]
															}
														},
														{
															title : "Tesouraria",
															id : "tesouraria",
															hidden : true,
															iconCls : "silk-tesouraria",
															root : {
																children : [
																		{
																			text : "Contribuintes",
																			name : "tesouraria",
																			leaf : true,
																			iconCls : "silk-user",
																			eXtype : "ContribuinteLista"
																		},
																		{
																			text : "Movimentações",
																			name : "tesouraria",
																			leaf : true,
																			iconCls : "silk-tesouraria",
																			eXtype : "MovimentacaoLista"
																		} ]
															}
														},
														{
															title : "Escola Dominical",
															id : "ebd",
															hidden : true,
															iconCls : "silk-ebd",
															root : {
																children : [
																		{
																			text : "Classes",
																			name : "ebd",
																			leaf : true,
																			iconCls : "no-icon",
																			eXtype : "ClasseLista"
																		},
																		{
																			text : "Professores",
																			name : "ebd",
																			leaf : true,
																			iconCls : "silk-membro",
																			eXtype : "ProfessorLista"
																		},
																		{
																			text : "Alunos",
																			name : "ebd",
																			leaf : true,
																			iconCls : "silk-user",
																			eXtype : "AlunoLista"
																		},
																		{
																			text : "Histórico de classe",
																			name : "ebd",
																			leaf : true,
																			iconCls : "silk-historico-classe",
																			eXtype : "HistoricoClasseLista"
																		},
																		{
																			text : "Histórico de aluno",
																			name : "ebd",
																			leaf : true,
																			iconCls : "silk-historico-aluno",
																			eXtype : "HistoricoAlunoLista"
																		} ]
															}
														},
														{
															title : "Administração",
															id : "administracao",
															hidden : true,
															iconCls : "silk-admin",
															root : {
																children : [
																		{
																			text : "Módulos",
																			name : "administracao",
																			leaf : true,
																			iconCls : "silk-modulo",
																			eXtype : "ModuloLista"
																		},
																		{
																			text : "Usuários",
																			name : "administracao",
																			leaf : true,
																			iconCls : "silk-user",
																			eXtype : "UsuarioLista"
																		},
																		{
																			text : "Departamentos",
																			name : "administracao",
																			leaf : true,
																			iconCls : "no-icon",
																			eXtype : "DepartamentoLista"
																		},
																		{
																			text : "Funções",
																			name : "administracao",
																			leaf : true,
																			iconCls : "no-icon",
																			eXtype : "FuncaoLista"
																		},
																		{
																			text : "Histórico de ações",
																			name : "administracao",
																			leaf : true,
																			iconCls : "silk-historico-acao",
																			eXtype : "HistoricoAcaoLista"
																		} ]
															}
														},
														{
															title : "Configuração",
															id : "configuracao",
															iconCls : "silk-configuracao",
															root : {
																children : [
																		{
																			text : "Alterar Senha",
																			name : "alterarSenha",
																			leaf : true,
																			iconCls : "silk-key",
																			eXtype : "AlterarSenha"
																		},
																		{
																			text : "Temas",
																			name : "tema",
																			leaf : true,
																			iconCls : "silk-tema",
																			eXtype : "Temas"
																		} ]
															}
														} ]
											}, this.tabPanelCentral ]
								});
						this.storeModulosUsuario = new Ext.data.JsonStore(
								{
									url : "include/administracao/moduloAction.php?action=listarModulosUsuario",
									root : "rows",
									fields : [ {
										name : "id_fonte"
									}, {
										name : "usuario"
									}, {
										name : "senha"
									}, {
										name : "tema"
									} ],
									listeners : {
										scope : this,
										load : function(a) {
											this.tema = a.getAt(0).json.tema;
											var b = (this.tema == 21) ? "lib/ext3.2.1/resources/css/xtheme-gray.css"
													: "lib/ext3.2.1/temas/"
															+ this.tema
															+ "/css/ext-all.css";
											Ext.util.CSS.swapStyleSheet("tema",
													b);
											Ext.state.Manager.set("tema", b);
											a.data.each(function(c) {
												Ext.getCmp(c.get("id_fonte"))
														.show()
											});
											if (SHA1(a.getAt(0).json.usuario) == a
													.getAt(0).json.senha) {
												this.exibirJanelaAlterarSenha();
												msgAlerta("Favor alterar sua senha")
											}
										}
									}
								});
						this.storeModulosUsuario.load();
						Principal.superclass.constructor.apply(this, arguments)
					},
					onNodeClick : function(c) {
						Ext.getBody().mask("Carregando...");
						var a = c.text;
						if (a == "Alterar Senha") {
							this.exibirJanelaAlterarSenha()
						} else {
							if (a == "Temas") {
								this.storeModulosUsuario.load( {
									scope : this,
									callback : function() {
										this.tema = this.storeModulosUsuario
												.getAt(0).data.tema;
										this.exibirJanelaTema()
									}
								})
							} else {
								var b = this.tabPanelCentral.items
										.find(function(d) {
											return d.title === a
										});
								Ext.require.moduleUrl = "js/"
										+ c.attributes.name + "/";
								Ext.require(c.attributes.eXtype, function() {
									if (!b) {
										b = this.tabPanelCentral.add( {
											title : a,
											iconCls : c.attributes.iconCls,
											xtype : c.attributes.eXtype
										})
									}
									this.tabPanelCentral.activate(b);
									Ext.getBody().unmask()
								}, this)
							}
						}
					},
					novaJanelaAlterarSenha : function() {
						if (!this.janelaAlterarSenha) {
							this.janelaAlterarSenha = new AlterarSenha()
						}
						return this.janelaAlterarSenha
					},
					exibirJanelaAlterarSenha : function() {
						Ext.require.moduleUrl = "js/geral/";
						Ext.require("AlterarSenha", function() {
							this.novaJanelaAlterarSenha();
							this.janelaAlterarSenha.show();
							Ext.getBody().unmask()
						}, this)
					},
					novaJanelaTema : function() {
						if (!this.janelaTema) {
							this.janelaTema = new Tema()
						}
						return this.janelaTema
					},
					exibirJanelaTema : function() {
						Ext.require.moduleUrl = "js/geral/";
						Ext.require("Tema", function() {
							this.novaJanelaTema();
							this.janelaTema.setIdTema(this.tema);
							this.janelaTema.show();
							Ext.getBody().unmask()
						}, this)
					}
				});
Ext.onReady(function() {
	Ext.QuickTips.init();
	Ext.form.CompositeField.prototype.combineErrors = false;
	new Principal();
	setTimeout(function() {
		Ext.get("Ploading").remove();
		Ext.get("Ploading-mask").fadeOut( {
			easing : "easeOut",
			duration : 0.7,
			remove : true
		})
	}, 250)
});